<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="wt.workflow.engine.WfActivity"%>
<%@page import="wt.workflow.work.WorkItem"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="wt.workflow.engine.ProcessData"%>
<%@page import="wt.maturity.PromotionNotice"%>
<%@page import="wt.part.WTPart"%>
<%@page import="wt.workflow.engine.WfVariable"%>
<%@page import="wt.doc.WTDocument"%>
<%@page import="shmged.com.shlcm.workflow.setparticipant.TpWorkflowHelper"%>
<%
	String baseUrl = new URLFactory().getBaseHREF();
	String tempoid=request.getParameter("oid");
	ReferenceFactory rf=new ReferenceFactory();
	WorkItem item=(WorkItem)rf.getReference(tempoid).getObject();
	WfActivity wa= (WfActivity)item.getSource().getObject();
	List list=wa.getUserEventList();
	Persistable pbo=(Persistable)item.getPrimaryBusinessObject().getObject();
	String tpSubject = "";
	String tpState = "";
	if(pbo instanceof WTDocument){
		WTDocument doc=(WTDocument)pbo;
		tpSubject = doc.getName();
		tpState = doc.getLifeCycleState().getDisplay();
	}else if(pbo instanceof WTPart){
		WTPart part=(WTPart)pbo;
		tpSubject = part.getName();
		tpState = part.getLifeCycleState().getDisplay();
	}else if(pbo instanceof PromotionNotice){
		PromotionNotice pn=(PromotionNotice)pbo;
		tpSubject = pn.getName();
		tpState = pn.getLifeCycleState().getDisplay();
	}
%>
<html>
<head>
<title>流程审批</title>
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript">var pageBaseUrl = "<%=baseUrl%>";</script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/jsp/com/shlcm/portal/js/main.js"></script>
<style type="text/css">
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
</style>
</head>
<body>
	<div style="margin: 10px 0;"></div>
	<div class="easyui-panel" title="<%=wa.getName()%>"
		style="width: 890px">
		<div style="margin: 10px 0;"></div>
		<form method="post" enctype="multipart/form-data" name="commitWork"
			id="commitWork">
			<table>
				<tr>
					<td width="80px" align="right">流程名称:</td>
					<td><%=wa.getName()%></td>
				</tr>
				<tr>
					<td align="right">主题:</td>
					<td><a href="javaScript:void(0)"
						onclick="subWorkItem('<%=tempoid%>')"><%=tpSubject%></a></td>
				</tr>
				<tr>
					<td align="right">状态:</td>
					<td><%=tpState%></td>
				</tr>
				<%
					ProcessData tpData =  wa.getContext();
					if(null != tpData){
					  WfVariable tpvars [] =  tpData.getVariableList();
					  for(int tpi = 0 ;tpi < tpvars.length;tpi++){
						if(tpvars[tpi].getName().startsWith("TpComments")){
				%>
				<tr>
					<td align="right"><%=tpvars[tpi].getDisplayName()%></td>
					<td><%=null == tpvars[tpi].getValue() ? "": tpvars[tpi].getValue()%></td>
				</tr>
				<%
					   }
					  }
					}
				%>
				<tr>
					<td align="right">意见:</td>
					<td><textarea id="userComments" name="userComments" cols="45"
							rows="5"></textarea></td>
				</tr>
				<%
					if(TpWorkflowHelper.isSetupParticipants(tempoid, "setupParticipants")){
				%>
				<tr>
					<td colspan="2"><br />
						<hr color="#95B8E7" /> <br /> <%@ include
							file="/shmged/jsp/com/shlcm/workflow/setparticipant/TaskFormTemplate.jsp"%>
						<br />
						<hr color="#95B8E7" /></td>
				</tr>
				<%}%>
				<%
					for(int i=0;i<list.size();i++){
				%>
				<tr>
					<td align="right" colspan="2"><%=list.get(i)%><input
						type="radio" name="userEvent" value="<%=list.get(i)%>"></input></td>
				</tr>
				<%}%>

				<tr>
					<td align="center" colspan="4"><label> <a
							href="javascript:void(0)" class="easyui-linkbutton"
							onclick="commitWorkItem()">提交</a> <a href="javascript:void(0)"
							class="easyui-linkbutton" onclick="clearForm1()">清除</a>
					</label></td>
				</tr>
			</table>
		</form>
	</div>

	<script type="text/javascript">
function commitWorkItem(){
	    var select="";
		for(var i=0;i<userEvent.length;i++){
			if(userEvent[i].checked){
				select=userEvent[i].value;
			}
		}
		var oid="<%=tempoid%>";
		var users = "";
		var setUsers = "false";
		if("undefined" == typeof addPrincipalMap){
			var users = "";
			for(var i = 0 ; i < addPrincipalMap.length; i ++){
				users = users+addPrincipalMap[i].roleName;
				for(var j = 0 ; j < addPrincipalMap[i].userArray.length; j ++){
					users = users + "`"+addPrincipalMap[i].userArray[j];
				}
				if( i < addPrincipalMap.length-1){
					users = users + ":";
				}
			}
			setUsers = "true";
		}
		
		var comments=document.getElementById('userComments').value;
		var url='<%=baseUrl%>shmged/jsp/com/shlcm/workflow/setparticipant/jspCommitWorkItem.jsp';
		var idata = {
				oid : oid,
				select : select,
				users : encodeURIComponent(users),
				comments : comments,
				setUsers : setUsers
	    };
		jQuery.post(url, idata, function(data) {
				if (data.indexOf("SUCCEED") != -1) {
					alert("任务完成,关闭当前窗口");
					window.close();
				} else {
					alert(data);
				}
			});
		}
	</script>

</body>
</html>


